home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue35
/
editnew
/
EDITNEW.ZIP
/
EDEMONEW.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-05-25
|
9KB
|
331 lines
{Demo of EditNew. Coment in ReadENew.Txt}
unit EDemoNew;
interface
uses
{$IFDEF WIN32}Windows,{$ELSE}Winprocs,WinTypes,{$ENDIF}
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, EditNew, Mask, DBCtrls, DB, DBTables;
type
TForm1 = class(TForm)
EditN1: TEditN;
EditN2: TEditN;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
EditN3: TEditN;
EditN4: TEditN;
EditN5: TEditN;
EditN6: TEditN;
EditN7: TEditN;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Panel1: TPanel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
EditN8: TEditN;
Label19: TLabel;
BitBtn1: TBitBtn;
Label15: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
EditN9: TEditN;
EditN10: TEditN;
MEditN1: TMEditN;
Label23: TLabel;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Label24: TLabel;
Label25: TLabel;
Table1: TTable;
DataSource1: TDataSource;
DBEditN1: TDBEditN;
DbEditN: TLabel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
BitBtn5: TBitBtn;
EditN11: TEditN;
Label26: TLabel;
Label27: TLabel;
EditN12: TEditN;
Label28: TLabel;
Label29: TLabel;
DBEditN2: TDBEditN;
Label30: TLabel;
procedure EditN1Change(Sender: TObject);
procedure EditN2Change(Sender: TObject);
procedure EditN3Change(Sender: TObject);
procedure EditN4Change(Sender: TObject);
procedure EditN5Change(Sender: TObject);
procedure EditN6Change(Sender: TObject);
procedure EditN7Change(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure EditN9Change(Sender: TObject);
procedure EditN10Change(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DBEditN1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure EditN11Exit(Sender: TObject);
procedure EditN12Exit(Sender: TObject);
private
IntArray : array [1..100] of Integer; // Array of integer value in memory
nEdit : array [1..10] of TEditN; // Array of new array in runtime dreate
p : array [1..10] of Pointer; // Pointer to conection nEdit[..] to IntArray[..]
nLabel : array [1..10] of TLabel; // Array of Label
iIndex : Integer; // Index of the array all
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
// Sample of create dBase Table in Runtime and assign value.
// The values are assigned after to the array IntArray[1..100]
with Table1 do begin
// Assign property to table
DataBaseName := ExtractFilePath(Application.ExeName);
TableName := 'Table1';
TableType := ttdBase;
// Create Table
with FieldDefs do begin
Clear;
Add('Field1', ftInteger, 0, False);
Add('Field2', ftString, 25, False);
end;
CreateTable;
// Assign value to the table
Open;
for i := 1 to 100 do begin
Append;
FieldByName('Field1').AsInteger := i;
FieldByName('Field2').AsString := 'Field 2 Recno ' + IntToStr(i);
Post;
end;
// Assign DataSource to the table
DbEditN1.DataSource := DataSource1;
DbEditN1.DataField := 'Field1';
DbEditN2.DataSource := DataSource1;
DbEditN2.DataField := 'Field2';
// Assign the value of the table to IntArray[1..100]
First;
for i := 1 to 100 do begin
IntArray[i] := Table1.FieldByName('Field1').AsInteger;
Next;
end;
First;
end;
end;
procedure TForm1.EditN1Change(Sender: TObject);
begin
Label1.Caption := EditN1.Text;
EditN9.SetFloat(EditN1.ValueFloat);
EditN10.SetInteger(EditN1.ValueInteger);
end;
procedure TForm1.EditN2Change(Sender: TObject);
begin
Label2.Caption := EditN2.Text;
EditN9.SetFloat(EditN2.ValueFloat);
EditN10.SetInteger(EditN2.ValueInteger);
end;
procedure TForm1.EditN3Change(Sender: TObject);
begin
Label3.Caption := EditN3.Text;
end;
procedure TForm1.EditN4Change(Sender: TObject);
begin
Label4.Caption := EditN4.Text;
end;
procedure TForm1.EditN5Change(Sender: TObject);
begin
Label5.Caption := EditN5.Text;
end;
procedure TForm1.EditN6Change(Sender: TObject);
begin
Label6.Caption := EditN6.Text;
end;
procedure TForm1.EditN7Change(Sender: TObject);
begin
Label7.Caption := EditN7.Text;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.EditN9Change(Sender: TObject);
begin
Label15.Caption := FloatToStr(EditN9.ValueFloat);
end;
procedure TForm1.EditN10Change(Sender: TObject);
begin
Label20.Caption := IntToStr(EditN10.ValueInteger);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var
i,ie,il : Integer;
begin
iIndex := 1; // Index of IntArray[1..100]
il := 16; // Top of nLabel[1]
ie := 30; // Top of nEdit[1]
for i := 1 to 10 do begin
// Create array of Label of conection of array to see
nLabel[i] := TLabel.Create(Form1);
nLabel[i].Parent := Form1;
nLabel[i].Caption := 'IntArray[' + IntToStr(i) + '] -> NEdit[' + IntToStr(i) + ']';
nLabel[i].Top := il + ((i-1) * 36);
nLabel[i].Left := 380;
nLabel[i].Font.Color := clMaroon;
// Create array of new EditN in runtime
nEdit[i] := TEditN.Create(Form1);
nEdit[i].Top := ie + ((i-1) * 36);
nEdit[i].Left := 380;
nEdit[i].EditKeyByTab := #13;
nEdit[i].EditPrecision := 2;
nEdit[i].EditType := etInteger; // For type Double, change to etFloat
// and IntArray to Type Double
nEdit[i].Parent := Form1;
// Assign EditN[1..10] to IntArray[1..100] (1..10 to start)
p[i] := @IntArray[i];
nEdit[i].SetPtrToData(p[i]);
end;
// Update value of IntArray[..] on the nEdit[..]
for i := 1 to 10 do NEdit[i].Update;
NEdit[1].SetFocus;
BitBtn2.Enabled := False;
BitBtn3.Enabled := True;
BitBtn4.Enabled := True;
BitBtn5.Enabled := True;
SpeedButton1.Enabled := True;
SpeedButton2.Enabled := True;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
var
i : Integer;
begin
// Clear the nEdit array
for i := 1 to 10 do nEdit[i].Destroy;
for i := 1 to 10 do nLabel[i].Destroy;
BitBtn2.Enabled := True;
BitBtn3.Enabled := False;
BitBtn4.Enabled := False;
BitBtn5.Enabled := False;
SpeedButton1.Enabled := False;
SpeedButton2.Enabled := False;
EditN1.SetFocus;
end;
procedure TForm1.BitBtn4Click(Sender: TObject);
var
i : Integer;
begin
// To increase/decrease the array IntArray and assign value in nEdit[..]
for i := iIndex to iIndex + 9 do begin
if Sender = BitBtn4 then IntArray[i] := IntArray[i] + 1; // Increase
if Sender = BitBtn5 then IntArray[i] := IntArray[i] - 1; // Decrease
end;
for i := 1 to 10 do NEdit[i].Update;
end;
procedure TForm1.DBEditN1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
// Move in the Table with cursor arrow key
if (Key = VK_DOWN) then Table1.Next;
if (Key = VK_UP) then Table1.Prior;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
i,j : Integer;
begin
// Move the nEdit array on the value of IntArray to up
if iIndex < 90 then iIndex := iIndex + 10
else Exit;
i := 1;
for j := iIndex to iIndex + 9 do begin
nEdit[i].SetPtrToData(@IntArray[j]); // Change the assign nEdit[1..10] to
// IntArray[iIndex..iIndex + 9]
nEdit[i].Update;
nLabel[i].Caption := 'IntArray[' + IntToStr(j) + '] -> NEdit[' + IntToStr(i) + ']';
Inc(i)
end;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
var
i,j : Integer;
begin
// Move the nEdit array on the value of IntArray to down
if iIndex > 1 then iIndex := iIndex - 10
else Exit;
i := 1;
for j := iIndex to iIndex + 9 do begin
nEdit[i].SetPtrToData(@IntArray[j]);
nEdit[i].Update;
nLabel[i].Caption := 'IntArray[' + IntToStr(j) + '] -> NEdit[' + IntToStr(i) + ']';
Inc(i)
end;
end;
procedure TForm1.EditN11Exit(Sender: TObject);
begin
Label28.Caption := FloatToStr(EditN11.ValueFloat) + ' - ' +
FormatDateTime('dd' + DateSeparator + 'mm' + DateSeparator +
'yyyy', EditN11.ValueDate);
end;
procedure TForm1.EditN12Exit(Sender: TObject);
begin
Label29.Caption := FloatToStr(EditN12.ValueFloat) + ' - ' +
FormatDateTime('hh' + TimeSeparator + 'mm' + TimeSeparator +
'ss', EditN12.ValueTime);
end;
end.